const express = require('express');
const router = express.Router();
const { body } = require('express-validator');
const TencentCloudCommon = require('tencentcloud-sdk-nodejs-common');
const CommonClient = TencentCloudCommon.CommonClient;
const secretId = process.env.TCADP_SECRETID; 
const secretKey = process.env.TCADP_SECRETKEY; 
const logger = require('../utils/logger');
const clientConfig = {
  credential: {
    secretId: secretId,
    secretKey: secretKey
  },
  region: 'ap-guangzhou',
  profile: {
    httpProfile: {
      endpoint: 'lke.ap-guangzhou.tencentcloudapi.com'
    }
  }
};
const client = new CommonClient(
  'lke.ap-guangzhou.tencentcloudapi.com',
  '2023-11-30',
  clientConfig
);
router.post("/getDemoToken",async (req,res)=>{
  try {
    const bodyData = req.body;
    const params = {
      'Type': 5,
      'BotAppKey': bodyData.appId,
      'VisitorBizId': bodyData.appId.substring(0, 5)
    };
    const apiResponse = await client.request('GetWsToken', params);
    res.json({
      status:200,
      message:"对话读取成功",
      data:apiResponse
    })
  } catch (error) {
    res.json({
      status: 9000,
      message: "请求错误！"
    })
    logger.error(error);
  }
  
})
module.exports = router;